// pages/detail/detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailInfo:{
      "Id": 96,
      "ShopId": 2,
      "GoodsNo": "1666748",
      "DataStatus": 2,
      "Title": "国产|乐宠乐喷|宠物室内喷雾300ml",
      "Classify": 102,
      "ClassifyName": "护理",
      "GoodsImage": "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023518452522.jpg",
      "Stock": 10,
      "SaleAmount": 65,
      "CreateDate": "2018-11-04T18:35:24.000Z",
      "UpdateDate": "2018-11-20T16:20:39.000Z",
      "Brand": "乐宠乐喷",
      "OrderNum": 0,
      "SwiperImgList": [
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023518452522.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181119174911711201.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181114120643144118.jpg"
      ],
      "DetailImgList": [
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023609436883.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023609077672.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023609780116.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023610467126.jpg",
        "https://www.maohz.com/mhzapi/api/Common/ImageFile/goodsimgderek20181105023610170702.jpg"
      ]
    },
    current: 0,
    goodsNo:'',
  },
  //自定义事件 -- 跳转回首页
  goToHome:function(){
    wx.switchTab({
      url: '/pages/home/home'
    })
  },

  //自定义事件 -- 咨询
  enquery:function(){
    wx.makePhoneCall({
      phoneNumber: '15899784568',
    })
  },

  //自定义事件 -- 跳转到购物车
  goToCart:function(){
    wx.switchTab({
      url: '/pages/cart/cart'
    })
  },

  //自定义事件 -- 加入购物车
  addToCart:function(){
    // let self = this;
    console.log('我是购物车')
    wx.request({
      url: 'https://ys.lumingx.com/api/miniapps/addCart',
      data: {
        userId:'32977',
        quantity:1,
        goodsId:this.data.goodsNo,
      },
      method: 'POST',
      dataType: 'json',
      success: (res) => {
        console.log(res)
        if(res.data && res.data.success){
          wx.showToast({
            title: '加入购物车成功',
            icon:'success',
            duration:2000,
          })
        }
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  //自定义事件 -- 立即购买
  buynow:function(){
    console.log('立即购买')
  },

  //自定义事件 -- 获取商品详情
  getDetailData:function(){
    // let this=this;
    wx.request({
      url: 'https://ys.lumingx.com/api/miniapps/getWXGoodsInfo',
      data:{
        goodsNo:this.data.goodsNo  || ""
      },
      header:{'content-type':'application/json'},//默认
      success:res=>{
        console.log(res.data)
        let result = res.data;
        if(result && result.data){
          this.setData({
            detailInfo:result.data
          })
        }
      },
    })
  },

  //自定义事件 -- 全屏预览产品图片
  previewImage:function(){
    wx.previewImage({
      current:this.data.detailInfo.SwiperImgList[this.data.current],
      urls: this.data.detailInfo.SwiperImgList,
    })
  },

  // 自定义事件 -- 幻灯片切换
  swiperChange: function(e){
    //console.log('11111111')
    //console.log(e)
    let currentNum = e.detail.current;
    this.setData({
      current: currentNum
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    //一进入页面就获取goodsNo
    this.data.goodsNo = options.goodsNo;
    this.getDetailData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})